package com.example.spzx.Service.impl;

import cn.hutool.core.date.DateUtil;
import com.example.spzx.Mapper.OrderStatisticsMapper;
import com.example.spzx.Service.OrderInfoService;
import com.example.spzx.model.dto.order.OrderStatisticsDto;
import com.example.spzx.model.entity.order.OrderStatistics;
import com.example.spzx.model.vo.order.OrderStatisticsVo;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.List;
import java.util.stream.Collectors;

@Service
public class OrderInfoServiceImpl implements OrderInfoService {
    @Resource
    private OrderStatisticsMapper orderStatisticsMapper;

    public OrderStatisticsVo getOrderStaticsData(OrderStatisticsDto orderStatisticsDto){
        List<OrderStatistics> orderStatisticsList=orderStatisticsMapper.selectList(orderStatisticsDto);
        List<String> datelist=orderStatisticsList.stream().map(orderStatistics -> DateUtil.format(orderStatistics.getOrderDate(),"yyyy-MM-dd")).collect(Collectors.toList());
        List<BigDecimal> amountlist=orderStatisticsList.stream().map(OrderStatistics::getTotalAmount).collect(Collectors.toList());
        OrderStatisticsVo orderStatisticsVo=new OrderStatisticsVo();
        orderStatisticsVo.setDateList(datelist);
        orderStatisticsVo.setAmountList(amountlist);
        return orderStatisticsVo;
    }
}
